
# -*- encoding=utf-8 -*-
# 1、使用4号触发器（两个红外反射传感器）和5号脉冲（SG90舵机）
# 2、触发红外对射1打开抬杆（舵机控制），触发红外对射2关闭抬杆

from froModuleDrivers.generalDeviceDriver import GeneralDeviceDriver
from froModuleDrivers.nioManager import NioManager
import time
from froModuleDrivers import LOGGER


# LOGGER.set_lvl("debug")

driver = GeneralDeviceDriver("192.168.50.110", 4001)
manager = NioManager(driver)
manager.run()

driver.showVersion()
driver.setWaitTime(0.4) # 设置指令返回的等待时间为0.4秒
while True:
    trigger = driver.getTriggerStatus(4) # 获取触发器状态
    # print(trigger)
    if trigger[0] == 0:
        print(f"前探头已被触发，打开抬杆")
        driver.setServoAngle(5,90) # 控制舵机为90°
    elif trigger[1] == 0:
        print(f"后探头已被触发，关闭抬杆")
        driver.setServoAngle(5,39) # 控制舵机为39°

manager.shutdownGracefully() # 等待指令执行完毕后系统退出
